<script setup lang="ts">
import { computed } from 'vue'
import { ElIcon } from 'element-plus'

interface Props {
  icon?: string
  title: string
  badge?: number
  active?: boolean
  to?: string
}

const props = withDefaults(defineProps<Props>(), {
  icon: '',
  active: false,
  to: ''
})

const emit = defineEmits(['click'])

const classes = computed(() => ({
  'nav-item': true,
  'is-active': props.active
}))

const handleClick = () => {
  emit('click')
}
</script>

<template>
  <div :class="classes" @click="handleClick">
    <el-icon v-if="icon" class="nav-icon">
      <component :is="icon" />
    </el-icon>
    <span class="nav-title">{{ title }}</span>
    <el-badge v-if="badge && badge > 0" :value="badge" class="nav-badge" />
  </div>
</template>

<style scoped>
.nav-item {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 56px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.nav-item:hover {
  background-color: var(--el-menu-hover-bg-color);
}

.nav-item.is-active {
  color: var(--el-menu-active-color);
}

.nav-icon {
  margin-right: 8px;
  font-size: 18px;
}

.nav-title {
  font-size: 14px;
}

.nav-badge {
  margin-left: 8px;
}
</style>